﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TP2.XNA_Game
{
    static class TypeExtensions
    {
        public static bool Implements<T>(this Type type)
        {
            return type.GetInterfaces().Any(@interface => @interface == typeof(T));
        }

        public static bool HasAttribute<T>(this Type type)
        {
            return type.GetCustomAttributes(typeof(T), true).Any();
        }

        public static T GetAttribute<T>(this Type type) where T : class
        {
            return type.GetCustomAttributes(typeof(T), true).First() as T;
        }

        public static T CreateInstance<T>(this Type type, params object[]args) where T : class
        {
            return Activator.CreateInstance(type, args) as T;
        }
    }
}
